package com.xxx.ware.ware_manage_sys.controller.warehouse;

import com.xxx.ware.ware_manage_sys.bean.dto.WebResultDto;
import com.xxx.ware.ware_manage_sys.bean.dto.WsDetailQueryDto;
import com.xxx.ware.ware_manage_sys.bean.dto.WsDetailUpdateSaveDto;
import com.xxx.ware.ware_manage_sys.bean.vo.ResultVo;
import com.xxx.ware.ware_manage_sys.bean.vo.WsDetailVo;
import com.xxx.ware.ware_manage_sys.service.IWsDetailService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@Api(tags = "仓库管理模块")
@RestController
@RequestMapping("/wms/wsdetail")
@MapperScan("com.xxx.ware.ware_manage_sys.mapper")
@Slf4j
public class WsDetailController {

    @Autowired
    private IWsDetailService wsDetailService;

    @PostMapping("/list")
    @ApiOperation(value = "仓库列表", notes = "仓库列表", httpMethod = "POST")
    private ResultVo<WebResultDto<WsDetailVo>> list(@RequestBody WsDetailQueryDto wsDetailQueryDto){
        try {
            return ResultVo.data(wsDetailService.getWareList(wsDetailQueryDto));
        } catch (Exception e) {
            log.error("查询仓库列表失败，对应失败原因：" + e);
            return ResultVo.fail("查询仓库列表失败");
        }
    }

    @PostMapping("/saveWs")
    @ApiOperation(value = "添加仓库", notes = "添加仓库", httpMethod = "POST")
    public ResultVo<Boolean> save(@RequestBody @Validated WsDetailUpdateSaveDto wsDetailUpdateSaveDto){
        try {
            return ResultVo.data(wsDetailService.saveWs(wsDetailUpdateSaveDto));
        } catch (Exception e) {
            log.error("添加仓库失败，对应失败原因：" + e);
            return ResultVo.fail("添加仓库失败");
        }
    }

    @PostMapping("/updateWare")
    @ApiOperation(value = "更新仓库", notes = "更新仓库", httpMethod = "POST")
    public ResultVo<Boolean> updateWare(@RequestBody @Validated WsDetailUpdateSaveDto wsDetailUpdateSaveDto){
        try {
            return ResultVo.data(wsDetailService.updateWare(wsDetailUpdateSaveDto));
        } catch (Exception e) {
            log.error("更新仓库信息失败，对应失败原因：" + e);
        }
        return ResultVo.fail("更新仓库信息失败");
    }

    @PostMapping("/removeWare")
    @ApiOperation(value = "删除仓库", notes = "删除仓库", httpMethod = "POST")
    public ResultVo<Boolean> removeWare(@RequestParam("id") Long id){
        try {
            return ResultVo.data(wsDetailService.removeWare(id));
        } catch (Exception e) {
            log.error("删除仓库失败，对应失败原因：" + e);
            return ResultVo.fail("删除仓库失败");
        }
    }


}
